package com.gdust.hzx.manager.controller;

import com.gdust.hzx.manager.service.CategoryBrandService;
import com.gdust.spzx.common.log.annotation.Log;
import com.gdust.spzx.common.log.enums.OperatorType;
import com.gdust.hzx.model.dto.product.CategoryBrandDto;
import com.gdust.hzx.model.entity.product.Brand;
import com.gdust.hzx.model.entity.product.CategoryBrand;
import com.gdust.hzx.model.vo.common.Result;
import com.gdust.hzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: CategoryBrandController
 * Package: com.gdust.spzx.manager.controller
 * Description:分类品牌控制类
 * 分类品牌管理就是将分类的数据和品牌的数据进行关联，分类数据和品牌数据之间的关系是多对多的关系，因此需要单独使用一张数据表来存储该数据
 *
 * @Author syun
 * @Create 2024/12/21 16:10
 * @Version 1.0
 */
@RestController// @RestController: 专用于restful风格的注解 = @Controller (控制器) + @ResponseBody (方法返回值为json)
@RequestMapping(value = "/admin/product/categoryBrand")
public class CategoryBrandController {
    //注入分类品牌表的service
    @Autowired
    private CategoryBrandService categoryBrandService;


    /**
     * //分类品牌条件分页查询
     * @param page
     * @param limit
     * @param categoryBrandDto
     * @return
     */
//    @Log(title = "分类品牌条件分页查询",businessType = 0,operatorType = OperatorType.MANAGE)
    @GetMapping("/{page}/{limit}")
    public Result<PageInfo<CategoryBrand>> findByPage(@PathVariable Integer page,
                                                      @PathVariable Integer limit,
                                                      CategoryBrandDto categoryBrandDto){
        //分页查询分类商品
        PageInfo<CategoryBrand> pageInfo = categoryBrandService.findByPage(page,limit,categoryBrandDto);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }


    /**
     * 添加分类品牌
     * @param categoryBrand
     * @return
     */
    @Log(title = "添加分类品牌",businessType = 1,operatorType = OperatorType.MANAGE)
    @PostMapping("/save")
    public Result save(@RequestBody CategoryBrand categoryBrand){
        //自定义方法：添加分类品牌
        categoryBrandService.save(categoryBrand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /***
     * 修改分类品牌
     * @param categoryBrand
     * @return
     */
    @Log(title = "修改分类品牌",businessType = 2,operatorType = OperatorType.MANAGE)
    @PutMapping("/updateById")
    public Result updateById(@RequestBody CategoryBrand categoryBrand){
        //自定义方法：修改分类品牌
        categoryBrandService.updateById(categoryBrand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 删除分类品牌
     * @param id
     * @return
     */
    @Log(title = "删除分类品牌",businessType = 3,operatorType = OperatorType.MANAGE)
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Long id){
        //删除分类品牌
        categoryBrandService.deleteById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 加载品牌数据
     * @param categoryId 品牌id
     * @return
     */
    @GetMapping("/findBrandByCategoryId/{categoryId}")
    public Result findBrandByCategoryId(@PathVariable Long categoryId){
        //自定义方法：加载品牌数据
        List<Brand> brandList = categoryBrandService.findBrandByCategoryId(categoryId);
        return Result.build(brandList,ResultCodeEnum.SUCCESS);
    }


}
